package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询所有分类
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByPid(@RequestParam("pid")Long pid) {
        List<CategoryDTO> categories = categoryService.queryCategoryByPid(pid);
        return ResponseEntity.ok(categories);
    }

    /**
     * 根据品牌id查询所有分类
     * @param bid
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByBid(@RequestParam("id") Long bid) {
        List<CategoryDTO> categories = categoryService.queryCategoryByBid(bid);
        return ResponseEntity.ok(categories);
    }

    /**id
     * 根据分类id的集合查询所有的分类
     * @param ids
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByIds(@RequestParam("ids") List<Long> ids) {
        List<CategoryDTO> categories = categoryService.queryCategoryByIds(ids);
        return ResponseEntity.ok(categories);
    }

    /**
     * 根据分类id查询所有分类集合
     */
    @GetMapping("/{id}")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByCid(@PathVariable("id") Long id) {
        List<CategoryDTO> categories = categoryService.queryCategoryByCid(id);
        return ResponseEntity.ok(categories);
    }
}
